//
//  ShoppingViewController.m
//  Teacher
//
//  Created by cong on 15/11/13.
//  Copyright © 2015年 liangdianxiong. All rights reserved.
//

#import "ShoppingViewController.h"
#import "MyLayout.h"
#import "TextFiel.h"
#import "CrvHeadView.h"
#import "DataObject.h"
#import "Grade.h"
#import "Subject.h"
#import "Publisher.h"
@interface ShoppingViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet CommonTableView *tvShop;


@property (strong,nonatomic) UIScrollView *sv_image;
@property(nonatomic,strong)NSArray *imageNames;
@property(nonatomic,strong)UIPageControl *pageControl;

@end

@implementation ShoppingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"%@",NSHomeDirectory());
    
    
    

//    
//    DataObject * obj = [DataObject new];
//    obj.strName = @"1111";
//    obj.strSchool = @"2222";
//    
//    
//    
//    
//    //插入
////    [FMDBHelper insertObject:obj];
//    
//    
//   NSMutableArray * arr = [FMDBHelper query:[DataObject tableName]];
//    NSLog(@"%@",arr);
//    //转化对象
//    DataObject * obj2 = [[DataObject alloc]initWithDictionary:[arr lastObject]];
//    
//
//    
//    //查找
//    NSMutableArray * arr2 = [FMDBHelper query:[DataObject tableName] where:@"strName=1111 AND strSchool=2222", nil];
//    
//    
//    
//    
//    NSMutableArray * arr3 = [FMDBHelper query:[DataObject tableName] where:@"strName=1111", nil];
//    
//       NSLog(@"%@",arr3);
//    
//    
//    for (NSDictionary *dit in arr3) {
//        
//         DataObject * obj2 = [[DataObject alloc]initWithDictionary:dit];
//
//obj2.strName = @"梁";
////        obj2.ID = @"1";
//        [FMDBHelper updateObject:obj2];
////        [FMDBHelper update:[DataObject tableName] keyValues:dit];
//        
//    }
////
//    
//   BOOL res =  [FMDBHelper remove:[DataObject tableName] where:@"strName='梁'"];
//    
//    
//    if (res==NO) {
//        
//    }
    
  
    
    
   
    
    
    
    
    
    
    
    
    //读取某个表的全部数据
    
    
    //还原对象
       NSMutableArray * arr = [FMDBHelper query:[Grade tableName]];
    
    for (NSDictionary * dict in arr) {
        
        
        Grade * grade = [[Grade alloc]initWithDictionary:dict];
     
        
        NSLog(@"----%@",grade.gradeName);
    }
    
     //接口数据缓存、持久化
//    AFHTTPRequestOperationManager * afm = [AFHTTPRequestOperationManager manager];
//    
//    afm.responseSerializer = [AFJSONResponseSerializer serializer];//申明返回的结果是json类型
//    afm.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//如果报接受类型不一致请替换一致text/html或别的
//
//    [afm POST:@"http://pdcaedu.com/exam/apinocheck/getExamBase" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
//        NSLog(@"%@",responseObject);
//        
//        
//        
//        NSArray * arrGrade = responseObject[@"grade"];
//         NSArray * arrsubject = responseObject[@"subject"];
//         NSArray * arrPublisher = responseObject[@"publisher"];
//        
//    
//        for (NSDictionary * dict in arrGrade) {
//            
//            Grade * grade = [[Grade alloc]initWithDictionary:dict];
//            
//            if ([FMDBHelper query:[Grade tableName] where:[NSString stringWithFormat:@"gradeName='%@'",grade.gradeName], nil].count==0) {
//                 [FMDBHelper insertObject:grade];
//            }
//           
//        }
//        
//        for (NSDictionary *dict in arrsubject) {
//            Subject *subject=[[Subject alloc]initWithDictionary:dict];
//            if ([FMDBHelper query:[Subject tableName] where:[NSString stringWithFormat:@"subjectName='%@'",subject.subjectName], nil].count==0) {
//                [FMDBHelper insertObject:subject];
//            }
//        }
//        
//        
//        for (NSDictionary *dict in arrPublisher) {
//            
//            
//            
//            Publisher *publisher=[[Publisher alloc ]initWithDictionary:dict];
//           
//            if ([FMDBHelper query:[Publisher tableName] where:[NSString stringWithFormat:@"publisherName='%@'",publisher.publisherName], nil].count==0) {
//                [FMDBHelper insertObject:publisher];
//            }
//        }
//        
//        
//        
//        
//    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
//        
//    }];
    

    

//      CrvHeadView * crvHeadView = [[[NSBundle mainBundle]loadNibNamed:@"CrvHeadView" owner:self options:nil] firstObject];
  
    
    _tvShop.arr_section = @[@20,@20,@20,@20,@20];
    
    [_tvShop addGroupNibWithData:@{} andHeadName:@"CrvHeadView"];
        [_tvShop addNibWithEntity:@{@"cell":@"CCellShop1"} andCellName:@"CellShop1" andSection:1];
    
    
    
    
     [_tvShop addGroupNibWithData:@{} andHeadName:@"HeadView"];
    
        [_tvShop addNibWithEntity:@{@"cell":@"CCellShop"} andCellName:@"CellShop1" andSection:2];
    
    
     [_tvShop addGroupNibWithData:@{} andHeadName:@"HeadView"];
    
    [_tvShop addNibWithEntity:@{} andCellName:@"CellShop3" andSection:3];
    [_tvShop addNibWithEntity:@{} andCellName:@"CellShop3" andSection:3];
    
    
     [_tvShop addGroupNibWithData:@{} andHeadName:@"HeadView"];
    
     [_tvShop addNibWithEntity:@{@"cell":@"CCellShop4"} andCellName:@"CellShop1" andSection:4];
    
//         [_tvShop addNibWithEntity:@{@"cell":@"CCellShop3"} andCellName:@"CellShop1"];
    
//        _cvShop.headSize = CGSizeMake(320, 154);
//        [_cvShop addHeaderNibWithEntity:@{} andViewName:@"CrvHeadView" andSection:0];
//    
//        UIEdgeInsets inset = {10,5,10,5};
//        [_cvShop setSection:0 withInset:inset];
//        for (int i=0; i<9; i++) {
//            [_cvShop addNibWithEntity:@{} andCellName:@"CCellShop1" andSection:0];
//        }
//    
//    
//    for (int i=0; i<4; i++) {
//                [_cvShop addNibWithEntity:@{} andCellName:@"CCellShop" andSection:0];
//    }
    
}


-(NSArray *)imageNames{
    if (!_imageNames) {
        _imageNames=@[@"1.jpg",@"5.png",@"5.png",@"5.png"];
    }
    return _imageNames;
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int index = scrollView.contentOffset.x/SCREEN_WIDTH;
    NSLog(@"-----%d----%f",index,scrollView.contentOffset.x);
    _pageControl.currentPage = index;
}




@end
